﻿using System;
using System.Net;
using System.IO;
using System.Data;
using System.Text;
using System.Xml;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Utilities;
using Microsoft.SharePoint.Portal;
using Microsoft.SharePoint.Administration;
using Microsoft.SharePoint.WebControls;
using Microsoft.Office.Server;
using Microsoft.Office.Server.UserProfiles;
using Ko;

namespace KoPages.CONTROLTEMPLATES.userControls
{
    public partial class _TestInfo : UserControl
    {

        #region Members

        KoEnvironment koEnv = new KoEnvironment();
        KoWS_Helper koWS = new KoWS_Helper(); 

        #endregion

        protected void Page_Load(object sender, EventArgs e)
        {
            // for view only admins
            SPUtility.EnsureSiteAdminAccess(Microsoft.SharePoint.SPContext.Current.Web);


        }

        protected void btnViewCurUserInfo_Click(object sender, EventArgs e)
        {
            oBody.Text = "";
            SPUser user = SPContext.Current.Web.CurrentUser;
            if (user == null)
                oBody.Text = "Anonymous";
            else
            {
                StringBuilder sb = new StringBuilder();
                sb.Append(
@"<br />User ID - " + user.ID
+ @"<br />LoginName - " + user.LoginName
+ @"<br />LoginName - " + user.Name
+ @"<br />Notes - " + user.Notes
+ @"<br />Notes - " + user.Email);

                sb.Append(@"<br Roles - />");
                foreach (SPRole role in user.Roles)
                    sb.Append(" ; " + role.Name);
                sb.Append(@"<br Groups - />");
                foreach (SPGroup grp in user.Groups)
                    sb.Append(" ; " + grp.Name);

                oBody.Text = sb.ToString();
            }

        }

        protected void btnViewAppSettings_Click(object sender, EventArgs e)
        {
            oBody.Text = "";
            StringBuilder sb = new StringBuilder();
            sb.Append(@"<hr>AXAPTAConnect = " + koEnv.GetAppSetting("AXAPTAConnect"));
            sb.Append(@"<hr>DB04Connect = " + koEnv.GetAppSetting("DB04Connect"));
            sb.Append(@"<hr>MySqlMainSrvConnect = " + koEnv.GetAppSetting("MySqlMainSrvConnect"));
            sb.Append(@"<hr>BIConnect = " + koEnv.GetAppSetting("BIConnect"));
            sb.Append(@"<hr>1CConnect = " + koEnv.GetAppSetting("1CConnect"));
            sb.Append(@"<hr>DomainName = " + koEnv.GetAppSetting("DomainName"));
            sb.Append(@"<hr>ADServer = " + koEnv.GetAppSetting("ADServer"));
            sb.Append(@"<hr>ADUser = " + koEnv.GetAppSetting("ADUser"));
            sb.Append(@"<hr>ADPass = " + koEnv.GetAppSetting("ADPass"));
            sb.Append(@"<hr>ProxyDomainName = " + koEnv.GetAppSetting("ProxyDomainName"));
            sb.Append(@"<hr>ProxyAddress = " + koEnv.GetAppSetting("ProxyAddress"));
            sb.Append(@"<hr>ProxyUID = " + koEnv.GetAppSetting("ProxyUID"));
            sb.Append(@"<hr>ProxyPwd = " + koEnv.GetAppSetting("ProxyPwd"));
            sb.Append(@"<hr>WebServiceUser = " + koEnv.GetAppSetting("WebServiceUser"));
            sb.Append(@"<hr>WebServicePass = " + koEnv.GetAppSetting("WebServicePass"));
            sb.Append(@"<hr>ADOffice = " + koEnv.GetAppSetting("ADOffice"));
            oBody.Text = sb.ToString();
        }

        protected void btnViewUsersList_Click(object sender, EventArgs e)
        {

            DataTable tbl = new DataTable();
            List<string> errList = new List<string>();
            Exception err = koWS.GetSPUsersList(ref tbl, ref errList);

            if (err != null)
            {
                oBody.Text = "Error - " + err.Message;
            }
            else
            {
                gv.DataSource = tbl;
                gv.DataBind();
            }

        }

        
    }


}
